/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
    vector<string> ret;
public:
    void dfs(TreeNode*root,string path)
    {
       if(root->left==nullptr&&root->right==nullptr)
       {
            path+=to_string(root->val);
            ret.push_back(path);
            return;
       }
       path+=to_string(root->val);
       path+="->";
    if(root->left) dfs(root->left,path);
    if(root->right) dfs(root->right,path);

       
    }
    vector<string> binaryTreePaths(TreeNode* root) 
    {
      if(root) dfs(root,"");
       return ret;
    }
};